package cn.study.controller;


import cn.study.entity.StudyIntegral;
import cn.study.service.StudyIntegralService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 积分表 前端控制器
 * </p>
 *
 * @author qiao
 * @since 2020-06-22
 */
@Controller
@Slf4j
@RequestMapping("/study-integral")
public class StudyIntegralController {
    @Resource
    StudyIntegralService studyRoleService;


    @GetMapping("/list")
    public String list(Model model, @RequestParam(value="pn",defaultValue="1") Integer pn,
                       @RequestParam(value="paginalsize",defaultValue = "5") Integer paginalsize)
    {
        PageHelper.startPage(pn, paginalsize);

        List<StudyIntegral> list=studyRoleService.getlist();
        PageInfo pInfo=new PageInfo(list,10);
        model.addAttribute("pInfo",pInfo);
        model.addAttribute("paginalsize",paginalsize);
        return "study_integral";
    }
    @GetMapping("/upd")
    public String upd(Integer id,Model model)
    {
        StudyIntegral role=studyRoleService.getById(id);
        model.addAttribute("list",role);
        return "study_integral_upd";
    }

    @PostMapping("/integralupd")
    public String roleupd(Model model,StudyIntegral role)
    {
        studyRoleService.updateById(role);

        return "redirect:/study-integral/list";
    }
}

